const path = require("path");
const fs = require("fs");

function getPostsSidebar(pathMd = "fe/suanfa") {
  const postsPath = path.join(__dirname, "..", pathMd); // 指定 Markdown 页面保存的文件夹路径
  const postsFiles = fs.readdirSync(postsPath); // 获取该文件夹内的所有文件名
  // const childrens = []
  const sidebar = postsFiles.map((filename) => {
    const name = filename.replace(/\.md$/, ""); // 获取文件名，去除后缀 .md
    let path = `${pathMd}/${name}`;
    return {
      text: name,
      link: path,
    };
  });
  console.log(sidebar);
  return sidebar;
}
module.exports = {
  title: "悄悄的卷，然后卷死所有人",
  description: "这是一个奇怪的地方",
  base: "/blobview/",
  themeConfig: {
    nav: [
      { text: "Home", link: "/" },
      {
        text: "前端君",
        items: [
          { text: "面试八股文", link: "/fe/secondary/interviews/network" },
          { text: "算法大卷", link: "/fe/algorithm" },
          { text: "坑你太美", link: "/fe/errormd/chrome插件开发指南" },
        ],
      },
      {
        text: "稀奇君",
        items: [{ text: "web3",link: "/fe/secondary/interviews/network" }],
      },
      {
        text: "杂谈君",
        link: "/b",
      },
    ],
    sidebar: {
      "/fe/algorithm": getAlgorithmSidebar(),
      "/fe/errormd/chrome插件开发指南": ClinentKengNiTaiMei(),
      "/fe/secondary/interviews/network": getGuideSidebar(),
      "/fe/secondary/Javascript/javascript": JavaScriptRooture(),
      '/fe/secondary/webpack/webpack构建流程':ClientBuild()
    },
  },
};

function getGuideSidebar() {
  return [
    {
      text: "面试八股文",
      children: [
        { text: "网络协议", link: "/fe/secondary/interviews/network" },
        { text: "模块化", link: "/fe/secondary/interviews/modular" },
        { text: "JavaScript", link: "/fe/secondary/Javascript/javascript" },
        { text: "浏览器", link: "/guide/getting-started" },
        { text: "性能优化", link: "/" },
        { text: "Vue", link: "/" },
        { text: "前端构建", link:"/fe/secondary/webpack/webpack构建流程"},
      ],
    },
  ];
}

function getAlgorithmSidebar() {
  return [
    {
      text: "算法大卷",
      children: getPostsSidebar(),
    },
  ];
}

function JavaScriptRooture() {
  return [
    {
      text: "JavaScript",
      children: [
        { text: "WeapMap", link: "/fe/secondary/Javascript/weakmap" },
        { text: "JS数据类型", link: "/fe/secondary/interviews/jstype" },
        {
          text: "如何实现一个深浅拷贝",
          link: "/fe/secondary/Javascript/jsCopy",
        },
        {
          text: "探究JS常见的6种继承方式",
          link: "/fe/secondary/Javascript/jicheng",
        },
        { text: "闭包", link: "/fe/secondary/Javascript/闭包" },
        { text: "变量提升", link: "/fe/secondary/Javascript/变量提升" },
        { text: "作用域", link: "/fe/secondary/Javascript/作用域" },
        { text: "数据类型", link: "/fe/secondary/Javascript/js数据类型" },
      ],
    },
  ];
}

function ClinentKengNiTaiMei() {
  return [
    {
      text: "坑你太美",
      children: getPostsSidebar("fe/errormd"),
    },
  ];
}

function ClientBuild() {
  return [
    {
      text: "构建",
      children: getPostsSidebar("fe/secondary/Webpack"),
    },
  ];
}